package com.boarsoft.dubbo;

import org.apache.dubbo.config.ReferenceConfig;
import org.springframework.beans.factory.FactoryBean;


public class DubboReferenceFactory implements FactoryBean<Object> {
	private volatile Object refObject;
	private Class<?> refClazz;
	private ReferenceConfig<Object> referenceConfig;

	@Override
	public Object getObject() throws Exception {
		if (refObject == null) {
			synchronized (referenceConfig) {
				if (refObject == null) {
					refObject = referenceConfig.get();
				}
			}
		}
		return refObject;
	}

	@Override
	public Class<?> getObjectType() {
		return refClazz;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	public Object getRefObject() {
		return refObject;
	}

	public void setRefObject(Object refObject) {
		this.refObject = refObject;
	}

	public Class<?> getRefClazz() {
		return refClazz;
	}

	public void setRefClazz(Class<?> refClazz) {
		this.refClazz = refClazz;
	}

	public ReferenceConfig<Object> getReferenceConfig() {
		return referenceConfig;
	}

	public void setReferenceConfig(ReferenceConfig<Object> referenceConfig) {
		this.referenceConfig = referenceConfig;
	}

}
